﻿using System;
using System.Web.Mvc;
using System.Collections.Generic;

namespace Caramel.Web.Mvc.Validation
{
	public class AutoModelValidatorContainer : ModelValidatorContainer
	{
		private readonly IList<IClassValidator> _overrides = new List<IClassValidator>();

		public AutoModelValidatorContainer()
		{
			this.Conventions = new ModelValidatorConventionContainer(this);
		}

		public ModelValidatorConventionContainer Conventions { get; private set; }

		public AutoModelValidatorContainer Override<T>(Action<ClassModelValidator<T>> validator)
		{
			var classValidatorOverride = Activator.CreateInstance<ClassModelValidator<T>>();
			validator(classValidatorOverride);
			_overrides.Add(classValidatorOverride);

			return this;
		}

		internal override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
		{
			//if (metadata.ContainerType != null)
			//{
			//    foreach (var convention in this.Conventions.Conventions.OfType<IModelValidatorPropertyConvention>())
			//    {
			//        if (convention.Accept(attributes, containerType, modelAccessor, modelType, propertyName))
			//        {
			//            //var metadata = new PropertyModelMetadata() as IModelMetadata;
			//            convention.Apply(attributes, containerType, modelAccessor, modelType, propertyName, metadata as PropertyModelMetadata);

			//            if (metadata != null)
			//            {
			//                this.Apply(metadata, modelMetadata);
			//            }
			//        }
			//    }
			//}

			throw new NotImplementedException();
		}
	}
}
